package nus.mtech.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

import nus.mtech.presentation.Console;

/**
 * To load properties file
 * 
 * @author Alvin Lee
 */

public class LoadConfig {
	/*private static String agent_users = "";
	private static String admin_users = "";
	public static final String FILE_SEP = File.separator;
	
	
	public LoadConfig() {
		String default_dir = System.getProperty("user.dir");
		BufferedReader in = null;
		try {
			in = new BufferedReader(new FileReader
					(default_dir + FILE_SEP + "data" + FILE_SEP + "system.properties"));
			String str = "";
			while ((str = in.readLine()) != null) {
			    readConfig(str);
			}
			in.close();
			in = null;
		} catch (Exception e) {
			e.printStackTrace();
		}
		finally {
			try {
				if (in != null)
					in.close();
			}
			catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
	
	private void readConfig(String line) {
		if (line.contains("admin.users")) {
			admin_users = line.substring(line.indexOf("=") + 1);
			if (!admin_users.equals("") && admin_users.indexOf("|") > 0) {
				String[] tempUsers = admin_users.split("\\|");
				int i = 0;
				while (i < tempUsers.length) {
					String[] result = tempUsers[i].split("\\,");
					Console.addAdminUser(result[0], result[1]);
					i++;
				}
			}
		}
		if (line.contains("agent.users")) {
			agent_users = line.substring(line.indexOf("=") + 1);
			if (!agent_users.equals("") && agent_users.indexOf("|") > 0) {
				String[] tempUsers = agent_users.split("\\|");
				int i = 0;
				while (i < tempUsers.length) {
					String[] result = tempUsers[i].split("\\,");
					Console.addAgentUser(result[0], result[1]);
					i++;
				}
			}
		}
		if (line.contains("company.address")) {
			String add = line.substring(line.indexOf("=") + 1).replaceAll(";",System.getProperty("line.separator"));
			
			Console.setCompanyAdd(add);
		}
	}
	
	public static String getAdminUsers() {
		return admin_users;
	}
	
	public static String getAgentUsers() {
		return agent_users;
	}*/
}
